#ifndef __LIB_AUTH_H__
#define __LIB_AUTH_H__

#include "yatengine.h"
#include "yatephone.h"
#include "framework.h"
using namespace TelEngine;

#define LICENSE_STRUCT_ID 2
#define ANDROID_STRUCT_ID 3

#define offsetof( TYPE, MEMBER ) ( (size_t) &( (TYPE *) 0)->MEMBER)

typedef struct _license {
	char	uuid[64];
	char	create_time[64];
	char	expire_time[64];
	char	description[512];
	int		permission;
	int		type;
} license;

typedef struct _android {
	char	uuid[64];
	char	build_brand[64];
	char	build_model[64];
	int		build_sdk_int;
	char	build_board[64];
	char	build_fingerprint[64];
	char	build_hardware[64];
	char	build_radio[64];
	char	build_time[64];
	char	wifi_mac_address[64];
	char	android_id[64];
	char	device_id[64];
	int		width_pixels;
	int		height_pixels;
	int		density_dpi;
	char	register_time[64];
	char	last_use_time[64];
} android;

class AuthThread;

class AuthModule : public Module {
public:
	AuthModule();
	~AuthModule();

	void startAuth();
	void stopAuth();
protected:
	virtual void initialize();
	virtual bool received(Message& msg, int id);
private:
	AuthThread *m_authThread;
};

class AuthThread : public SimpleThread {
public:
	AuthThread();
	virtual ~AuthThread();
	virtual void run();
	virtual void cleanup();
	virtual void exit();
private:
	volatile bool m_exit;
private:
	int process_data(android& and, char *data, int size);
	void response(SOCKET sock, android& and);
};

class ParamAddressEx : public ParamAddress
{
public:
	ParamAddressEx(void* address);
	virtual ~ParamAddressEx();
	void* getParam();
	char* getDescription();
	void* getObject(const String& name) const;
private:
	void* m_address;
};

#endif